package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Region;
import cn.wolfcode.trip.base.mapper.RegionMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.query.RegionQueryObject;
import cn.wolfcode.trip.base.service.IRegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RegionServiceImpl implements IRegionService {
    @Autowired
    private RegionMapper mapper;

    @Override
    public List<Region> selectList(RegionQueryObject qo) {
        if (qo.getParentId() == null) {
            List<Region> list = mapper.selectRoot();
            return list;
        }
        List<Region> list = mapper.selectChildren(qo);
        return list;
    }

    @Override
    public List<Region> selectAll() {

        return mapper.selectAll();
    }


    @Override
    public void saveOrUpdate(Region region) {
        if (region.getId() == null){
            mapper.insert(region);
        }else {
            mapper.updateByPrimaryKey(region);
        }
    }

    @Override
    public List<Region> listHot(Integer state) {
       return   mapper.selectByState(state);
    }
}
